from google.appengine.ext.db import *
from django.dispatch import dispatcher
import signals

class SignalizedModel(Model):
  def __init__(self, *args, **kwds):
    dispatcher.send(signal=signals.pre_init,
                    sender=SignalizedModel,
                    instance=self,
                    *args,
                    **kwds)
    dispatcher.send(signal=signals.pre_init,
                    sender=self.__class__,
                    instance=self,
                    *args,
                    **kwds)
    super(SignalizedModel, self).__init__(*args, **kwds)
    dispatcher.send(signal=signals.post_init,
                    sender=SignalizedModel,
                    instance=self,
                    *args,
                    **kwds)
    dispatcher.send(signal=signals.post_init,
                    sender=self.__class__,
                    instance=self,
                    *args,
                    **kwds)
  
  def put(self, *args, **kwds):
    dispatcher.send(signal=signals.pre_put,
                    sender=SignalizedModel,
                    instance=self,
                    *args,
                    **kwds)
    dispatcher.send(signal=signals.pre_put,
                    sender=self.__class__,
                    instance=self,
                    *args,
                    **kwds)
    super(SignalizedModel, self).put(*args, **kwds)
    dispatcher.send(signal=signals.post_put,
                    sender=SignalizedModel,
                    instance=self,
                    *args,
                    **kwds)
    dispatcher.send(signal=signals.post_put,
                    sender=self.__class__,
                    instance=self,
                    *args,
                    **kwds)

  def delete(self, *args, **kwds):
    dispatcher.send(signal=signals.pre_delete,
                    sender=SignalizedModel,
                    instance=self,
                    *args,
                    **kwds)
    dispatcher.send(signal=signals.pre_delete,
                    sender=self.__class__,
                    instance=self,
                    *args,
                    **kwds)
    super(SignalizedModel, self).delete(*args, **kwds)
    dispatcher.send(signal=signals.post_delete,
                    sender=SignalizedModel,
                    instance=self,
                    *args,
                    **kwds)
    dispatcher.send(signal=signals.post_delete,
                    sender=self.__class__,
                    instance=self,
                    *args,
                    **kwds)

class SignalizedExpando(Expando):
  def __init__(self, *args, **kwds):
    dispatcher.send(signal=signals.pre_init,
                    sender=SignalizedExpando,
                    instance=self,
                    *args,
                    **kwds)
    dispatcher.send(signal=signals.pre_init,
                    sender=self.__class__,
                    instance=self,
                    *args,
                    **kwds)
    super(SignalizedExpando, self).__init__(*args, **kwds)
    dispatcher.send(signal=signals.post_init,
                    sender=SignalizedExpando,
                    instance=self,
                    *args,
                    **kwds)
    dispatcher.send(signal=signals.post_init,
                    sender=self.__class__,
                    instance=self,
                    *args,
                    **kwds)
  
  def put(self, *args, **kwds):
    dispatcher.send(signal=signals.pre_put,
                    sender=SignalizedExpando,
                    instance=self,
                    *args,
                    **kwds)
    dispatcher.send(signal=signals.pre_put,
                    sender=self.__class__,
                    instance=self,
                    *args,
                    **kwds)
    super(SignalizedExpando, self).put(*args, **kwds)
    dispatcher.send(signal=signals.post_put,
                    sender=SignalizedExpando,
                    instance=self,
                    *args,
                    **kwds)
    dispatcher.send(signal=signals.post_put,
                    sender=self.__class__,
                    instance=self,
                    *args,
                    **kwds)

  def delete(self, *args, **kwds):
    dispatcher.send(signal=signals.pre_delete,
                    sender=SignalizedExpando,
                    instance=self,
                    *args,
                    **kwds)
    dispatcher.send(signal=signals.pre_delete,
                    sender=self.__class__,
                    instance=self,
                    *args,
                    **kwds)
    super(SignalizedExpando, self).delete(*args, **kwds)
    dispatcher.send(signal=signals.post_delete,
                    sender=SignalizedExpando,
                    instance=self,
                    *args,
                    **kwds)
    dispatcher.send(signal=signals.post_delete,
                    sender=self.__class__,
                    instance=self,
                    *args,
                    **kwds)